Background color is controlled using a set of utility classes prefixed with bg-. These classes allow you to easily apply various colors or gradients to the background of your elements.
Use classes like bg-red-500, bg-blue-400, etc., where the color name corresponds to Tailwind's built-in color palette (shades of red, blue, etc.). These classes offer various color intensities (e.g., 100 for light, 500 for medium, 900 for dark).
If you have defined custom colors in your Tailwind configuration, use classes like bg-custom-color.
Apply the bg-transparent class to remove any background color and make the element's background transparent.
<div class="box bg-blue-500"> This box has a blue background. </div>
<div class="box bg-transparent"> This box has a transparent background. </div>
Tailwind offers utility classes for applying linear and radial gradients to backgrounds. These classes use keywords like from-red-500, to-blue-700 to define the gradient's start and end colors.
Control the opacity of the background color using the bg-opacity class with values from 0 (fully transparent) to 100 (fully opaque). For example, bg-red-500 bg-opacity-50 creates a semi-transparent red background.
Apply responsive prefixes (e.g., md:bg-green-300) to change background colors based on screen sizes.
<div class="rounded-lg bg-gradient-to-r from-teal-400 to-blue-500 bg-opacity-75">
This element has a rounded shape with a teal to blue gradient background that's slightly transparent.
</div>